recode_domains <- function(x) {
    dplyr::case_when(
        # Mainstream media
        x == "abcnews.go.com" ~ "ABC",
        x == "bbc.com" ~ "BBC",
        x == "businessinsider.com" ~ "Business Insider",
        x == "buzzfeed.com" ~ "BuzzFeed",
        x == "cbsnews.com" ~ "CBS",
        x == "cnn.com" ~ "CNN",
        x == "theguardian.com" ~ "Guardian",
        x == "huffingtonpost.com" ~ "Huffington Post",
        x == "huffpost.com" ~ "Huffington Post",
        x == "msnbc.com" ~ "MSNBC",
        x == "latimes.com" ~ "LA Times",
        x == "newsweek.com" ~ "Newsweek",
        x == "npr.org" ~ "NPR",
        x == "nytimes.com" ~ "New York Times",
        x == "wsj.com" ~ "Wall Street Journal",
        x == "nbcnews.com" ~ "NBC News",
        x == "pbs.org" ~ "PBS",
        x == "thehill.com" ~ "The Hill",
        x == "politico.com" ~ "Politico",
        x == "time.com" ~ "Time",
        x == "usatoday.com" ~ "USA Today",
        x == "vice.com" ~ "Vice",
        x == "vox.com" ~ "Vox",
        x == "washingtonpost.com" ~ "Washington Post",

        # Left-wing media
        x == "alternet.org" ~ "Alternet",
        x == "theatlantic.com" ~ "Atlantic",
        x == "thedailybeast.com" ~ "Daily Beast",
        x == "theintercept.com" ~ "Intercept",
        x == "motherjones.com" ~ "Mother Jones",
        x == "newyorker.com" ~ "New Yorker",
        x == "salon.com" ~ "Salon",
        x == "slate.com" ~ "Slate",
        x == "thinkprogress.org" ~ "Think Progress",

        # Center-Right Media
        x == "americanthinker.com" ~ "American Thinker",
        x == "babylonbee.com" ~ "Babylon Bee",
        x == "bigleaguepolitics.com" ~ "Big League Politics",
        x == "bongino.com" ~ "Bongino",
        x == "breitbart.com" ~ "Breitbart",
        x == "circa.com" ~ "Circa",
        x == "cnsnews.com" ~ "CNS",
        x == "conservativereview.com" ~ "Conservative Review",
        x == "dailycaller.com" ~ "Daily Caller",
        x == "dailywire.com" ~ "Daily Wire",
        x == "disobedientmedia.com" ~ "Disobedient Media",
        x == "foxnews.com" ~ "Fox News",
        x == "fox5dc.com" ~ "Fox 5 DC",
        x == "freebeacon.com" ~ "Free Beacon",
        x == "frontpagemag.com" ~ "Front Page Magazine",
        x == "gellerreport.com" ~ "Geller Report",
        x == "hannity.com" ~ "Hannity",
        x == "heatst.com" ~ "Heat Street",
        x == "hotair.com" ~ "Hot Air",
        x == "infowars.com" ~ "Infowars",
        x == "intellihub.com" ~ "Intellihub",
        x == "newsbusters.org" ~ "NewsBusters",
        x == "newsmax.com" ~ "Newsmax",
        x == "newspunch.com" ~ "Your News Wire",
        x == "nationalreview.com" ~ "National Review",
        x == "nypost.com" ~ "New York Post",
        x == "oann.com" ~ "One America News",
        x == "pamelageller.com" ~ "Geller Report",
        x == "pjmedia.com" ~ "Pajamas Media",
        x == "realclearpolitics.com" ~ "RealClearPolitics",
        x == "redstate.com" ~ "Red State",
        x == "rushlimbaugh.com" ~ "Rush Limbaugh",
        x == "spectator.org" ~ "American Spectator",
        x == "theblaze.com" ~ "The Blaze",
        x == "thebulwark.com" ~ "The Bulwark",
        x == "theconservativetreehouse.com" ~ "Conservative Treehouse",
        x == "thedailysheeple.com" ~ "Daily Sheeple",
        x == "theepochtimes.com" ~ "Epoch Times",
        x == "thefederalist.com" ~ "Federalist",
        x == "thegatewaypundit.com" ~ "Gateway Pundit",
        x == "thepoliticalinsider.com" ~ "Political Insider",
        x == "therightscoop.com" ~ "Right Scoop",
        x == "townhall.com" ~ "Townhall",
        x == "trendingpolitics.com" ~ "Trending Politics",
        x == "truthfeed.com" ~ "Truthfeed",
        x == "twitchy.com" ~ "Twitchy",
        x == "washingtonexaminer.com" ~ "Washington Examiner",
        x == "washingtontimes.com" ~ "Washington Times",
        x == "weeklystandard.com" ~ "Weekly Standard",
        x == "westernjournal.com" ~ "Western Journal",
        x == "westernjournalism.com" ~ "Western Journal",
        x == "wjla.com" ~ "WJLA",
        x == "wnd.com" ~ "World Net Daily",
        x == "yournewswire.com" ~ "Your News Wire",
        x == "zerohedge.com" ~ "ZeroHedge",

        # RT/Sputnik
        x == "rt.com" ~ "RT",
        x == "sputniknews.com" ~ "Sputnik"
    ) |> factor(
        levels = c(
        # local news - do not display
          "Fox 5 DC", "WJLA",

        # mainstream media
        "ABC", "BBC", "Business Insider", "BuzzFeed",
        "CBS", "CNN", "MSNBC", "LA Times", "Newsweek", "NPR", "New York Times",
        "Wall Street Journal", "NBC News", "PBS", "The Hill", "Politico",
        "Time", "USA Today", "Washington Post",

        # left-wing media
        "Alternet","Atlantic", "Daily Beast", "Guardian", "Huffington Post", "Intercept",
        "Mother Jones", "New Yorker", "Salon", "Slate", "Think Progress", "Vice", "Vox",

        # Center-Right Media
        "Babylon Bee", "Circa", "CNS", "Conservative Review", "Daily Caller", "Daily Wire",
        "Fox News", "Free Beacon", "Hannity", "Heat Street",
        "Hot Air",  "NewsBusters", "Newsmax", "National Review", "New York Post",
        "Pajamas Media", "RealClearPolitics", "Red State", "Rush Limbaugh", "American Spectator",
        "The Blaze", "The Bulwark",  "Federalist",  "Townhall",  "Twitchy", "Washington Examiner",
        "Washington Times", "Weekly Standard",

        # far-right media
        "American Thinker", "Big League Politics", "Bongino", "Breitbart", "Disobedient Media", "Front Page Magazine",
        "Geller Report", "Infowars", "Intellihub", "One America News",
        "Conservative Treehouse", "Daily Sheeple", "Epoch Times", "Gateway Pundit",
        "Political Insider", "Right Scoop", "Trending Politics", "Truthfeed",
        "Western Journal", "World Net Daily", "Your News Wire", "ZeroHedge",

        # russia
        "RT", "Sputnik"),
        ordered = TRUE)
}


code_categories <- function(x) {
  dplyr::case_when(
    x == "RT" ~ "Russian Publishers",
    x == "Sputnik" ~ "Russian Publishers",
    x == "ABC" ~ "Mainstream Media",
    x == "BBC" ~ "Mainstream Media",
    x == "Business Insider" ~ "Mainstream Media",
    x == "BuzzFeed" ~ "Mainstream Media",
    x == "CBS" ~ "Mainstream Media",
    x == "CNN" ~ "Mainstream Media",
    x == "Guardian" ~ "Left-Wing Media",
    x == "Huffington Post" ~ "Left-Wing Media",
    x == "MSNBC" ~ "Mainstream Media",
    x == "LA Times" ~ "Mainstream Media",
    x == "Newsweek" ~ "Mainstream Media",
    x == "NPR" ~ "Mainstream Media",
    x == "New York Times" ~ "Mainstream Media",
    x == "Wall Street Journal" ~ "Mainstream Media",
    x == "NBC News" ~ "Mainstream Media",
    x == "PBS" ~ "Mainstream Media",
    x == "The Hill" ~ "Mainstream Media",
    x == "Politico" ~ "Mainstream Media",
    x == "Time" ~ "Mainstream Media",
    x == "USA Today" ~ "Mainstream Media",
    x == "Vice" ~ "Left-Wing Media",
    x == "Vox" ~ "Left-Wing Media",
    x == "Washington Post" ~ "Mainstream Media",
    x == "Alternet" ~ "Left-Wing Media",
    x == "Atlantic" ~ "Left-Wing Media",
    x == "Daily Beast" ~ "Left-Wing Media",
    x == "Intercept" ~ "Left-Wing Media",
    x == "Mother Jones" ~ "Left-Wing Media",
    x == "New Yorker" ~ "Left-Wing Media",
    x == "Salon" ~ "Left-Wing Media",
    x == "Slate" ~ "Left-Wing Media",
    x == "Think Progress" ~ "Left-Wing Media",
    x == "American Thinker" ~ "Far-Right Media",
    x == "Babylon Bee" ~ "Center-Right Media",
    x == "Big League Politics" ~ "Far-Right Media",
    x == "Bongino" ~ "Far-Right Media",
    x == "Breitbart" ~ "Far-Right Media",
    x == "Circa" ~ "Center-Right Media",
    x == "CNS" ~ "Center-Right Media",
    x == "Conservative Review" ~ "Center-Right Media",
    x == "Daily Caller" ~ "Center-Right Media",
    x == "Daily Wire" ~ "Center-Right Media",
    x == "Disobedient Media" ~ "Far-Right Media",
    x == "Fox News" ~ "Center-Right Media",
    x == "Fox 5 DC" ~ NA,
    x == "Free Beacon" ~ "Center-Right Media",
    x == "Front Page Magazine" ~ "Far-Right Media",
    x == "Geller Report" ~ "Far-Right Media",
    x == "Hannity" ~ "Center-Right Media",
    x == "Heat Street" ~ "Center-Right Media",
    x == "Hot Air" ~ "Center-Right Media",
    x == "Infowars" ~ "Far-Right Media",
    x == "Intellihub" ~ "Far-Right Media",
    x == "NewsBusters" ~ "Center-Right Media",
    x == "Newsmax" ~ "Center-Right Media",
    x == "National Review" ~ "Center-Right Media",
    x == "New York Post" ~ "Center-Right Media",
    x == "One America News" ~ "Far-Right Media",
    x == "Pajamas Media" ~ "Center-Right Media",
    x == "RealClearPolitics" ~ "Center-Right Media",
    x == "Red State" ~ "Center-Right Media",
    x == "Rush Limbaugh" ~ "Center-Right Media",
    x == "American Spectator" ~ "Center-Right Media",
    x == "The Blaze" ~ "Center-Right Media",
    x == "The Bulwark" ~ "Center-Right Media",
    x == "Conservative Treehouse" ~ "Far-Right Media",
    x == "Daily Sheeple" ~ "Far-Right Media",
    x == "Epoch Times" ~ "Far-Right Media",
    x == "Federalist" ~ "Center-Right Media",
    x == "Gateway Pundit" ~ "Far-Right Media",
    x == "Political Insider" ~ "Far-Right Media",
    x == "Right Scoop" ~ "Far-Right Media",
    x == "Townhall" ~ "Center-Right Media",
    x == "Trending Politics" ~ "Center-Right Media",
    x == "Truthfeed" ~ "Center-Right Media",
    x == "Twitchy" ~ "Center-Right Media",
    x == "Washington Examiner" ~ "Center-Right Media",
    x == "Washington Times" ~ "Center-Right Media",
    x == "Weekly Standard" ~ "Center-Right Media",
    x == "Western Journal" ~ "Far-Right Media",
    x == "WJLA" ~ NA,
    x == "World Net Daily" ~ "Far-Right Media",
    x == "Your News Wire" ~ "Far-Right Media",
    x == "ZeroHedge" ~ "Far-Right Media"
  )
}
